home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / ead / ead23.dms / ead23.adf / Listati / WCM.c < prev    next >
C/C++ Source or Header  |  1990-05-28  |  7KB  |  380 lines

  1. /* ***********************************************************************
  2.  
  3. Programma ........ Window Color Modifier
  4.  
  5. Versione ......... 1.0, 30 giugno 1989
  6.  
  7. Autore ........... Flavio Stanchina
  8.  
  9. Scopo ............ Modifica colori di finestra Workbench
  10.  
  11. Software ......... Lattice C V5.04 || Aztec C V5.0a
  12.  
  13. Sintassi ......... Vedi documentazione su EnigmA Amiga Disk 23
  14.  
  15. Make Lattice ..... LC -vbr -Lntv -rr -O -ms Wcm.c
  16.  
  17. Make Aztec C ..... CC -sb -so Wcm.c, LN wcm -lc
  18.  
  19. Note ............. Linkabile con modulo personalizzato da F.S.
  20.  
  21.                    Adattamenti marginale per Aztec C di Luigi Callegari
  22.  
  23. ********************************************************************* */
  24.  
  25. #include <libraries/dosextens.h>
  26. #include <intuition/intuition.h>
  27. #include <workbench/workbench.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30. #include <string.h>
  31. #include <stdio.h>
  32.  
  33. #ifdef LATTICE
  34. #  include <proto/all.h>
  35. #else
  36. #  include <functions.h>
  37. #endif
  38.  
  39. #define LENBUF 80
  40. #define VERS 33L
  41.  
  42. struct DosLibrary *DOSBase;
  43. struct IntuitionBase *IntuitionBase;
  44. struct Library *IconBase;
  45. struct Window *win;
  46. struct IntuiMessage *msg;
  47.  
  48. /* Le tre stringhe necessarie per contenere il nome dei file di input e
  49.  * i valori per le due penne.
  50.  */
  51. char file[LENBUF];
  52. char detpen[3] = "-1";
  53. char blkpen[3] = "-1";
  54.  
  55. /* La seguente struttura serve per garantire l' uso del topaz 8 ed evitare
  56.  * malfunzionamenti.
  57.  */
  58. struct TextAttr top80 = {
  59.     (STRPTR)"topaz.font",
  60.     TOPAZ_EIGHTY,
  61.     NULL,
  62.     NULL
  63. };
  64.  
  65. /* Gli array con la struttura dei bordi dei gadget e subito dopo le strut-
  66.  * ture Border per ogni gadget. I bordi per le due penne sono uguali quin-
  67.  * di viene usata la stessa struttura Border.
  68.  */
  69. SHORT border_file[] = { 0,0, 275,0, 275,11, 0,11, 0,0 };
  70. SHORT border_pens[] = { 0,0, 27,0, 27,11, 0,11, 0,0 };
  71.  
  72. struct Border file_border = {
  73.     -2, -2,        /* Origine relativa */
  74.     3, 0,        /* Penne (Fore/Back) */
  75.     JAM1,        /* Modo */
  76.     5,        /* Numero coppie di coord. */
  77.     border_file,    /* Matrice di coord. */
  78.     NULL        /* Prossima struttura */
  79. };
  80.  
  81. struct Border pens_border = {
  82.     -2, -2,
  83.     3, 0,
  84.     JAM1,
  85.     5,
  86.     border_pens,
  87.     NULL
  88. };
  89.  
  90. /* Le definizioni per i gadget stringa.
  91.  */
  92. struct StringInfo file_sinfo = {
  93.     file,
  94.     NULL,
  95.     0,
  96.     LENBUF,
  97.     0,
  98.     0, 0, 0, 0, 0,
  99.     0,
  100.     0,
  101.     NULL
  102. };
  103.  
  104. struct StringInfo detpen_sinfo = {
  105.     detpen,
  106.     NULL,
  107.     0,
  108.     3,
  109.     0,
  110.     0, 0, 0, 0, 0,
  111.     0,
  112.     -1,
  113.     NULL
  114. };
  115.  
  116. struct StringInfo blkpen_sinfo = {
  117.     blkpen,
  118.     NULL,
  119.     0,
  120.     3,
  121.     0,
  122.     0, 0, 0, 0, 0,
  123.     0,
  124.     -1,
  125.     NULL
  126. };
  127.  
  128. struct IntuiText go_itext = {
  129.     0, 1,
  130.     JAM2,
  131.     8, 2,
  132.     &top80,
  133.     "Modify",
  134.     NULL
  135. };
  136.  
  137. struct Image go_image = {
  138.     0, 0,    /* Offset */
  139.     64, 12,    /* Dimensions */
  140.     2,    /* Depth */
  141.     NULL,    /* Data */
  142.     0,    /* PlanePick */
  143.     0x1,    /* PlaneOnOff */
  144.     NULL    /* Next */
  145. };
  146.     
  147. /* Le definizioni vere e proprie dei gadget.
  148.  */
  149. struct Gadget go_gad = {
  150.     NULL,
  151.     -67, 24,
  152.     64, 12,
  153.     GADGIMAGE | GADGHCOMP | GRELRIGHT,
  154.     RELVERIFY,
  155.     BOOLGADGET,
  156.     (APTR)&go_image,
  157.     NULL,
  158.     &go_itext,
  159.     NULL,
  160.     NULL,
  161.     NULL,
  162.     NULL
  163. };
  164.  
  165. struct Gadget blkpen_gad = {
  166.     &go_gad,
  167.     188, 26,
  168.     24, 8,
  169.     NULL,
  170.     RELVERIFY | STRINGRIGHT | LONGINT,
  171.     STRGADGET,
  172.     (APTR)&pens_border,
  173.     NULL,
  174.     NULL,
  175.     NULL,
  176.     (APTR)&blkpen_sinfo,
  177.     NULL,
  178.     NULL
  179. };
  180.  
  181. struct Gadget detpen_gad = {
  182.     &blkpen_gad,
  183.     82, 26,
  184.     24, 8,
  185.     NULL,
  186.     RELVERIFY | STRINGRIGHT | LONGINT,
  187.     STRGADGET,
  188.     (APTR)&pens_border,
  189.     NULL,
  190.     NULL,
  191.     NULL,
  192.     (APTR)&detpen_sinfo,
  193.     NULL,
  194.     NULL
  195. };
  196.  
  197. struct Gadget file_gad = {
  198.     &detpen_gad,
  199.     42, 13,
  200.     272, 8,
  201.     NULL,
  202.     RELVERIFY,
  203.     STRGADGET,
  204.     (APTR)&file_border,
  205.     NULL,
  206.     NULL,
  207.     NULL,
  208.     (APTR)&file_sinfo,
  209.     NULL,
  210.     NULL
  211. };
  212.  
  213. /* Le strutture IntuiText con i nomi dei gadget.
  214.  */
  215. struct IntuiText blkpen_itext = {
  216.     1, 0,
  217.     JAM1,
  218.     120, 26,
  219.     &top80,
  220.     (UBYTE*)"BlockPen",
  221.     NULL
  222. };
  223.  
  224. struct IntuiText detpen_itext = {
  225.     1, 0,
  226.     JAM1,
  227.     6, 26,
  228.     &top80,
  229.     (UBYTE*)"DetailPen",
  230.     &blkpen_itext
  231. };
  232.  
  233. struct IntuiText file_itext = {
  234.     1, 0,
  235.     JAM1,
  236.     6, 13,
  237.     &top80,
  238.     (UBYTE*)"File",
  239.     &detpen_itext
  240. };
  241.  
  242. /* La definizione della finestra.
  243.  */
  244. struct NewWindow wcm_win = {
  245.     100, 100,
  246.     320, 47,
  247.     -1, -1,
  248.     GADGETDOWN | GADGETUP | CLOSEWINDOW,
  249.     WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | ACTIVATE | NOCAREREFRESH,
  250.     &file_gad,
  251.     NULL,
  252.     (UBYTE*)"WCM v1.0 by Flavio Stanchina",
  253.     NULL,
  254.     NULL,
  255.     0, 0,
  256.     0, 0,
  257.     WBENCHSCREEN
  258. };
  259.  
  260. /* La funzione main si limita a chiamare tutte le altre. E` stata messa al
  261.  * primo posto per poter eliminare le routine di startup col Lattice 5.0.
  262.  * Infatti in mancanza delle suddette routine la prima routine che compare
  263.  * e` la prima ad essere eseguita.
  264.  */
  265. void main( void )
  266. {
  267.     void err(char *);
  268.     BOOL wbhandle( void );
  269.  
  270.     register struct DiskObject *icon;
  271.     register long status;
  272.  
  273.     if(!(IntuitionBase = (struct IntuitionBase *)
  274.       OpenLibrary("intuition.library", VERS)))
  275.         return;
  276.  
  277.     if(!(IconBase = (struct Library *)
  278.       OpenLibrary("icon.library", VERS)))
  279.         goto end2;
  280.  
  281.     if(!(win = OpenWindow(&wcm_win)))
  282.         goto end1;
  283.  
  284.     PrintIText(win->RPort, &file_itext, 0, 0);
  285.     ActivateGadget(&file_gad, win, NULL);
  286.  
  287.     while( wbhandle() )
  288.     {
  289.         if(!(icon = (struct DiskObject *)GetDiskObject(file)))
  290.         {
  291.             err("Error reading icon file         ");
  292.             goto loop;
  293.         }
  294.  
  295.         if(icon->do_Type != WBDISK &&
  296.            icon->do_Type != WBDRAWER &&
  297.            icon->do_Type != WBGARBAGE)
  298.         {
  299.             err("Not type DISK, DRAWER or GARBAGE");
  300.             goto loop;
  301.         }
  302.  
  303.         icon->do_DrawerData->dd_NewWindow.DetailPen =
  304.           (UBYTE)detpen_sinfo.LongInt;
  305.         icon->do_DrawerData->dd_NewWindow.BlockPen =
  306.           (UBYTE)blkpen_sinfo.LongInt;
  307.  
  308.         status = PutDiskObject(file, icon);
  309.         FreeDiskObject(icon);
  310.     
  311.         if(status == 0) err("Error Writing icon file         ");
  312.         else err("Icon modified                   ");
  313.  
  314. loop: ;
  315.     }
  316.     
  317.     CloseWindow(win);
  318. end1:    CloseLibrary((struct Library *)IconBase);
  319. end2:    CloseLibrary((struct Library *)IntuitionBase);
  320.     return;
  321. }
  322.  
  323. void err(char *s)
  324. {
  325.     struct IntuiText err_itext = {
  326.         1, 0,
  327.         JAM2,
  328.         6, 37,
  329.         &top80,
  330.         NULL,
  331.         NULL
  332.     };
  333.  
  334.     err_itext.IText = s;
  335.     PrintIText(win->RPort, &err_itext, 0, 0);
  336.  
  337.     return;
  338. }
  339.  
  340. BOOL wbhandle( void )
  341. {
  342.     register struct Gadget *addr;
  343.     register ULONG class;
  344.  
  345.     for( ;; )
  346.     {
  347.         Wait( 1L << win->UserPort->mp_SigBit );
  348.  
  349.         while(msg = (struct IntuiMessage *)GetMsg(win->UserPort))
  350.         {
  351.             class = msg->Class;
  352.             addr = (struct Gadget *)msg->IAddress;
  353.             ReplyMsg((struct Message *)msg);
  354.  
  355.             switch(class)
  356.             {
  357.             case CLOSEWINDOW:
  358.             return(FALSE);
  359.  
  360.             case GADGETUP:
  361.             case GADGETDOWN:
  362.             if(addr == &go_gad)
  363.                 if(!file[0] ||
  364.                   !detpen[0] ||
  365.                   !blkpen[0])
  366.                     err("Input file and pens required    ");
  367.  
  368.                 else if(detpen_sinfo.LongInt > 3 ||
  369.                   detpen_sinfo.LongInt < -1 ||
  370.                   blkpen_sinfo.LongInt > 3 ||
  371.                   blkpen_sinfo.LongInt < -1)
  372.                     err("Pens must be from -1 to 3        ");
  373.  
  374.                 else return(TRUE);
  375.             }
  376.         }
  377.     }
  378. }
  379.  
  380.